package name.matthewgreet.example14.dto; import java.io.Serializable; import java.util.ArrayList; import java.util.Date; import java.util.EnumSet; import java.util.List; public class PrimeMinisterDTO implements Serializable { public enum Party {CONSERVATIVE, LABOUR, LIBERAL, WHIG}; public enum OtherCabinetPosition {BUSINESS, CHANCELLOR, CULTURE, DEFENCE, EDUCATION, ENERGY, ENVIRONMENT, FOREIGN, HEALTH, HOME, JUSTICE, LORD_CHANCELLOR, NORTHERN_IRELAND, SCIENCE, SCOTLAND, TRADE, TRANSPORT, WALES, WORK} private static final long serialVersionUID = -6937072630784482008L; private int id; private String name; private Date dateOfBirth; private List<Person> children; private String wikipediaEntry; private Party party; private String constituency; private Integer bestConstituencyMajority; private Short bestConstituencyYear; private EnumSet<OtherCabinetPosition> otherCabinetPositions; private List<DateRange> termsOfOffice = new ArrayList<>(); private Integer maxSeatsWon; private Short maxSeatsYear; private List<Integer> otherSeatsWon = new ArrayList<>(); public PrimeMinisterDTO() { super(); } public PrimeMinisterDTO(PrimeMinisterDTO other) { super(); this.id = other.id; this.name = other.name; this.dateOfBirth = other.dateOfBirth; this.children = new ArrayList<>(other.getChildren()); this.wikipediaEntry = other.wikipediaEntry; this.party = other.party; this.constituency = other.constituency; this.bestConstituencyMajority = other.bestConstituencyMajority; this.bestConstituencyYear = other.bestConstituencyYear; this.otherCabinetPositions = EnumSet.copyOf(other.otherCabinetPositions); this.termsOfOffice = new ArrayList<>(other.termsOfOffice); this.maxSeatsWon = other.maxSeatsWon; this.otherSeatsWon = new ArrayList<>(other.otherSeatsWon); } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Date getDateOfBirth() { return dateOfBirth; } public void setDateOfBirth(Date dateOfBirth) { this.dateOfBirth = dateOfBirth; } public List<Person> getChildren() { return children; } public void setChildren(List<Person> children) { this.children = children; } public String getWikipediaEntry() { return wikipediaEntry; } public void setWikipediaEntry(String wikipediaEntry) { this.wikipediaEntry = wikipediaEntry; } public Party getParty() { return party; } public void setParty(Party party) { this.party = party; } public String getConstituency() { return constituency; } public void setConstituency(String constituency) { this.constituency = constituency; } public Integer getBestConstituencyMajority() { return bestConstituencyMajority; } public void setBestConstituencyMajority(Integer bestConstituencyMajority) { this.bestConstituencyMajority = bestConstituencyMajority; } public Short getBestConstituencyYear() { return bestConstituencyYear; } public void setBestConstituencyYear(Short bestConstituencyYear) { this.bestConstituencyYear = bestConstituencyYear; } public EnumSet<OtherCabinetPosition> getOtherCabinetPositions() { return otherCabinetPositions; } public void setOtherCabinetPositions(EnumSet<OtherCabinetPosition> otherCabinetPositions) { this.otherCabinetPositions = otherCabinetPositions; } public List<DateRange> getTermsOfOffice() { return termsOfOffice; } public void setTermsOfOffice(List<DateRange> termsOfOffice) { this.termsOfOffice = termsOfOffice; } public Integer getMaxSeatsWon() { return maxSeatsWon; } public void setMaxSeatsWon(Integer maxSeatsWon) { this.maxSeatsWon = maxSeatsWon; } public Short getMaxSeatsYear() { return maxSeatsYear; } public void setMaxSeatsYear(Short maxSeatsYear) { this.maxSeatsYear = maxSeatsYear; } public List<Integer> getOtherSeatsWon() { return otherSeatsWon; } public void setOtherSeatsWon(List<Integer> otherSeatsWon) { this.otherSeatsWon = otherSeatsWon; } @Override public String toString() { final int maxLen = 10; return "PrimeMinisterDTO [id=" + id + ", " + (name != null ? "name=" + name + ", " : "") + (dateOfBirth != null ? "dateOfBirth=" + dateOfBirth + ", " : "") + (children != null ? "children=" + children.subList(0, Math.min(children.size(), maxLen)) + ", " : "") + (wikipediaEntry != null ? "wikipediaEntry=" + wikipediaEntry + ", " : "") + (party != null ? "party=" + party + ", " : "") + (constituency != null ? "constituency=" + constituency + ", " : "") + (bestConstituencyMajority != null ? "bestConstituencyMajority=" + bestConstituencyMajority + ", " : "") + (bestConstituencyYear != null ? "bestConstituencyYear=" + bestConstituencyYear + ", " : "") + (otherCabinetPositions != null ? "otherCabinetPositions=" + otherCabinetPositions + ", " : "") + (termsOfOffice != null ? "termsOfOffice=" + termsOfOffice.subList(0, Math.min(termsOfOffice.size(), maxLen)) + ", " : "") + (maxSeatsWon != null ? "maxSeatsWon=" + maxSeatsWon + ", " : "") + (maxSeatsYear != null ? "maxSeatsYear=" + maxSeatsYear + ", " : "") + (otherSeatsWon != null ? "otherSeatsWon=" + otherSeatsWon.subList(0, Math.min(otherSeatsWon.size(), maxLen)) : "") + "]"; } }